﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UI
{
    /// <summary>
    /// 组件的视图状态
    /// </summary>
    public class PartViewState
    {
        public string Name { get; set; }

        /// <summary>
        /// 状态信息
        /// </summary>
        public Dictionary<string, string> States { get; set; }

        public List<PartViewState> SubPartViewStateList { get; set; }


        public PartViewState(string partName)
        {
            this.Name = partName;

            States = new Dictionary<string, string>();
            SubPartViewStateList = new List<PartViewState>();
        }

        public void Set(string key, string value)
        {
            States.Add(key, value);
        }

        public void SetInt(string key, int value)
        {
            States.Add(key, value.ToString());
        }

        public string Get(string key)
        {
            if (States.ContainsKey(key))
            {
                return States[key];
            }
            return null;
        }

        /// <summary>
        /// 添加子组件的视图状态
        /// </summary>
        /// <param name="subPartViewState"></param>
        public void AddSubPartViewState(PartViewState subPartViewState)
        {
            SubPartViewStateList.Add(subPartViewState);
        }

        public PartViewState GetSubPartViewState(string partName)
        {
            for (int index = 0; index < SubPartViewStateList.Count; index++)
            {
                if (SubPartViewStateList[index].Name == partName)
                {
                    return SubPartViewStateList[index];
                }
            }
            return null;
        }
    }
}
